<template>
  <el-popover :placement="placement" trigger="click" width="300" popper-class="treeDiv">
    <el-tree
      ref="popupTree"
      :data="data"
      :props="props"
      :node-key="nodeKey"
      :default-checked-keys="defaultCheckedKey"
      :highlight-current="true"
      :expand-on-click-node="true"
      @current-change="currentChangeHandle"
    />
    <template #reference>
      <el-input :disabled="isDisable" :class="isInner?'inner':''" v-model="prop" readonly :placeholder="placeholder" style="cursor: pointer" />
    </template>
  </el-popover>
</template>

<script lang="ts">
export default {
  name: 'PopupTreeInput',
  props: {
    isInner:{
      type: Boolean,
      default: false,
    },
    data: {
      type: Array,
      required: true,
    },
    props: {
      type: Object,
    },
    prop: {
      type: String,
      default: '',
    },
    nodeKey: {
      type: String || Number,
    },
    placeholder: {
      type: String,
      default: '点击选择内容',
    },
    placement: {
      type: String,
      default: 'bottom-start',
    },
    defaultExpandAll: {
      type: Boolean,
      default: false,
    },
    defaultCheckedKey: {
      type: Array,
      default() {
        return []
      },
    },
    currentChangeHandle: {
      type: Function,
      default: null,
    },
    defaultKey: {
      type: String,
      default: '',
    },
    isDisable:{
      type: Boolean,
      default: false,
    }
  },
  setup(props) {
    console.log(props.data)

    return {}
  },
}
</script>

<style lang="scss">
.inner{
 width: 300px;
}
.treeDiv {
  max-height: 400px;
  overflow-y: auto;
}
</style>
